"""MxShopCp URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
# from django.contrib import admin
# from django.urls import path
from django.conf.urls import url, include
import xadmin
from MxShopCp.settings import MEDIA_ROOT
from django.views.static import serve
from rest_framework.documentation import include_docs_urls
from rest_framework.routers import DefaultRouter
from rest_framework_jwt.views import obtain_jwt_token
from goods.views import GoodsListViewSet, CategoryViewSet, BannerViewSet, IndexCategoryViewset
from trade.views import ShoppingCartViewSet
from users.views import SmsCodeViewSet, UserViewSet
from user_operation.views import UserFavViewSet, LeavingMessageViewSet, AddressViewSet

from rest_framework.authtoken import views

router = DefaultRouter()
# 配置goods的url
router.register(r'goods', GoodsListViewSet, base_name="goods")

# 配置category的url
router.register(r'category', CategoryViewSet, base_name="category")

# 获取轮播图
router.register(r'banners', BannerViewSet, base_name="banners")

# 首页商品系列数据
router.register(r'indexgoods', IndexCategoryViewset, base_name="indexgoods")

# 获取验证码
router.register(r'codes', SmsCodeViewSet, base_name="codes")

# 注册
router.register(r'users', UserViewSet, base_name="users")

# 收藏
router.register(r'userfavs', UserFavViewSet, base_name="userfavs")

# 留言
router.register(r'messages', LeavingMessageViewSet, base_name="messages")

# 收货地址
router.register(r'address', AddressViewSet, base_name="address")

# 购物车
router.register(r'shopcarts', ShoppingCartViewSet, base_name="shopcarts")

urlpatterns = [
    url('admin/', xadmin.site.urls),

    url(r'^media/(?P<path>.*)$', serve, {"document_root": MEDIA_ROOT}),

    url(r'^', include(router.urls)),

    url(r'docs/', include_docs_urls(title='慕学生鲜')),

    url(r'^api-auth/', include('rest_framework.urls')),

    # jwt的认证接口
    url(r'^login/', obtain_jwt_token),
]
